package com.ibiaoke.system.dao;

import com.ibiaoke.common.base.BaseDao;
import com.ibiaoke.common.base.Page;
import com.ibiaoke.common.consts.CommonConsts;
import com.ibiaoke.system.entity.XcxTopicPage;
import com.ibiaoke.system.entity.XcxTopicPageExample;
import com.ibiaoke.system.mapper.ShopMapper;
import com.ibiaoke.system.mapper.XcxTopicPageMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author Dragon
 * @date 2018/4/9/9:29;
 */
@Repository
public class XcxTopicPageDao extends BaseDao<XcxTopicPage,XcxTopicPageExample,Integer,XcxTopicPageMapper> {

    @Autowired
    private XcxTopicPageMapper xcxTopicPageMapper;
    @Override
    public XcxTopicPageMapper getMapper() {
        return xcxTopicPageMapper;
    }

    public List<XcxTopicPage> listTopicPage(Integer position, Integer showStatus, Page page) {
        XcxTopicPageExample example = new XcxTopicPageExample();
        XcxTopicPageExample.Criteria criteria = example.createCriteria().andDelStatusEqualTo(CommonConsts.NO);
        if(position!=null){
            criteria.andPositionEqualTo(position);
        }
        if(showStatus!=null){
            criteria.andShowStatusEqualTo(showStatus);
        }
        if(page!=null) {
            page.setTotalCount(countByExample(example));
            example.setLimitStart(page.limitStart());
            example.setLimitEnd(page.limitEnd());
        }
        example.setOrderByClause("sort");
        return selectByExample(example);
    }

    public List<XcxTopicPage> listTopicPageByShopId(Integer position, Integer shopId, Integer showStatus, Page page) {
        XcxTopicPageExample example = new XcxTopicPageExample();
        XcxTopicPageExample.Criteria criteria = example.createCriteria().andDelStatusEqualTo(CommonConsts.NO);
        if (position != null) {
            criteria.andPositionEqualTo(position);
        }
        if (showStatus != null) {
            criteria.andShowStatusEqualTo(showStatus);
        }
        if (shopId != null) {
            criteria.andShopIdEqualTo(shopId);
        }
        if (page != null) {
            page.setTotalCount(countByExample(example));
            example.setLimitStart(page.limitStart());
            example.setLimitEnd(page.limitEnd());
        }
        example.setOrderByClause("sort");
        return selectByExample(example);
    }
}
